package com.community.backend.controller;


import com.community.backend.pojo.Repair;
import com.community.backend.pojo.dto.RepairQueryDTO;
import com.community.backend.service.RepairService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/repair")
@Slf4j
public class RepairController {

    private final RepairService repairService;

    public RepairController(RepairService repairService) {
        this.repairService = repairService;
    }

    /**
     * 搜索,在分配维修人员时使用
     */
//    @GetMapping("/search")
//    public Result<List<RepairSearchVO>> search(RepairQueryDTO repairQueryDTO) {
//        List<RepairSearchVO> list = repairService.searchRoom(repairQueryDTO);
//        return Result.success(list);
//    }

    @GetMapping("/page")
    public Result<PageResult> page(RepairQueryDTO repairQueryDTO) {
        log.info("查询参数：{}", repairQueryDTO);
        PageResult pageResult = repairService.pageQuery(repairQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result save(@RequestBody Repair repair) {
        repairService.save(repair);
        return Result.success("添加成功");
    }
    @PutMapping
    public Result Update(@RequestBody Repair repair) {
        repairService.update(repair);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable Integer id) {
        repairService.deleteById(id);
        return Result.success("删除成功");
    }
}
